package com.yxq.mdt.app.modules.main.model;

import com.yxq.mdt.app.base.RespBase;
import com.yxq.mdt.app.base.ibase.IBaseModel;
import com.yxq.mdt.app.modules.main.bean.AppVersion;
import com.yxq.mdt.app.modules.main.bean.NameAndPhoneBean;
import com.yxq.mdt.app.modules.order.bean.OrderConfirmBean;
import com.yxq.mdt.app.net.ApiModel;
import com.yxq.mdt.app.net.BaseObserver;
import com.yxq.mdt.app.net.RetrofitFactory;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class AppModel implements IBaseModel {

    public void getSzyVersion(ApiModel.CommonCallback<AppVersion> callback) {

        RetrofitFactory.getJavaRetrofit().create(AppApi.class)
                .getSzyVersion("2")
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<AppVersion>() {
                    @Override
                    public void onFailure(Throwable e, boolean isNetWorkError) {
                        callback.onError(e.getMessage());
                    }

                    @Override
                    public void onSuccess(AppVersion respBase) {
                        callback.onSuccess(respBase);
                    }
                });
    }

    public void getNameAndPhone(ApiModel.CommonCallback<NameAndPhoneBean> callback) {

        RetrofitFactory.getPMRetrofit().create(AppApi.class)
                .getNameAndPhone()
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<RespBase<NameAndPhoneBean>>() {
                    @Override
                    public void onFailure(Throwable e, boolean isNetWorkError) {
                        callback.onError(e.getMessage());
                    }

                    @Override
                    public void onSuccess(RespBase<NameAndPhoneBean> respBase) {
                        if (respBase.getCode() == 200) {
                            callback.onSuccess(respBase.getData());
                        } else {
                            callback.onError(respBase.getMsg());
                        }
                    }
                });
    }

    public static void becomeTeamer(String orderId, String orderPrice, ApiModel.CommonCallback<String> callback) {

        RetrofitFactory.getPMRetrofit().create(AppApi.class)
                .becomeTeamer(orderId, orderPrice)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<RespBase<String>>() {
                    @Override
                    public void onFailure(Throwable e, boolean isNetWorkError) {
                        callback.onError(e.getMessage());
                    }

                    @Override
                    public void onSuccess(RespBase<String> respBase) {
                        if (respBase.getCode() == 200) {
                            callback.onSuccess(respBase.getData());
                        } else {
                            callback.onError(respBase.getMsg());
                        }
                    }
                });
    }

    @Override
    public void onDestroy() {

    }
}
